import os
import sys
import zipfile
import shutil
import time

version = "0.Alpha"
file = None
folder = None
name = None
config = None

## Builds Package
def mkPackage(folder,package):
	zf = zipfile.ZipFile(package, "w")
	for dirname, subdirs, files in os.walk(folder):
		zf.write(dirname)
		for filename in files:
			zf.write(os.path.join(dirname, filename))
	zf.close()
## Appends Package
def adPackage(file,package):
	zf = zipfile.ZipFile(package, "a" )
	zf.write(file)
## Unpacks Package
def unPackage(package,folder):
	zip = zipfile.ZipFile(package)
	zip.extractall(folder)
	
class readXML():
#	xmlPath = tmpFolder
	print(os.walk(tmpFolder))
	Name = "FooBar"

## Procecess arguments
args = sys.argv
i = 0
loop = True
while loop == True:
	try:
		package = args[i]
		if args[i] == "-f":
			file = args[next]
		if args[i] == "-F":
			folder = args[next]
		if args[i] == "-n":
			name = args[next]
		if args[i] == "-c":
			config = args[next]
		if args[i] == "-x":
			config = args[next]
		i += 1
	except:
		loop = False
	next = i + 1

## Preflight check
print("Starting...")
tmpFolder = str(round(time.time()))
tmpFolder.replace(".","")
os.makedirs(tmpFolder)
unPackage(package,tmpFolder)
print("Extracted to " + tmpFolder)
configFile = readXML()
#os.system("cls")
print(configFile.Name)
shutil.rmtree(tmpFolder)
print("...Done")